﻿using Beaker.Injection;

namespace Beaker.Specs
{
	public static class FactoryExtensions
	{
		/// <summary>
		/// Create a new Mock that implements the <see cref="IFactory{TService}"/> interface and returns the same given instance every time.
		/// </summary>
		/// <typeparam name="TService">The type of the service to return from the factory.</typeparam>
		/// <param name="instance">The instance to return from the factory.</param>
		/// <returns>A mock that implements the <see cref="IFactory{T}"/> interface and returns the same given instance every time.</returns>
		public static IFactory<TService> AsMockFactory<TService>(this TService instance)
			where TService : class
		{
			return new FactoryMockBuilder<TService>()
				.ReturningInstance(instance)
				.Build();
		}
	}
}
